/*
 * Copyright (C) 2012 yueyueniao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.wzm.moviepic.fragment;

import java.util.ArrayList;

import com.wzm.bean.AboutUsInfo;
import com.wzm.moviepic.R;
import com.wzm.moviepic.slidingmenu.Main1Activity;



import android.annotation.SuppressLint;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.ClipboardManager;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 本地下载数据
 * @author zhengzhiyou
 */
public class AboutUsFragment extends Fragment {

	private ListView aboutList = null;
	private AboutUsAdapter Adapter = null;
	private Context mContext;
	private ImageView btn_back;
	private ArrayList<AboutUsInfo> mlist = null;
	
	
	//手势
	private GestureDetector detector;
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContext = getActivity();
		
		View view = inflater.inflate(R.layout.fragment_aboutus, null);
		
		getInfo();
		aboutList = (ListView)view.findViewById(R.id.aboutlist);
		btn_back = (ImageView)view.findViewById(R.id.btn_imgback);
		Adapter = new AboutUsAdapter(mContext,mlist);
		aboutList.setAdapter(Adapter);
		
		
		detector = new GestureDetector(getActivity(),new OnGestureListener() {
			
			@Override
			public boolean onSingleTapUp(MotionEvent e) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public void onShowPress(MotionEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
					float distanceY) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public void onLongPress(MotionEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
					float velocityY) {
				// TODO Auto-generated method stub
				
				if (e1.getX() - e2.getX() > 120) {
					//Logger.info("向左...");
					((Main1Activity)mContext).showcenter();
		            return true;
		        } else if (e1.getX() - e2.getX() < -120) {
		        	{//本地资源页面
		        		FragmentTransaction t = getActivity().getSupportFragmentManager()
								.beginTransaction();
						t.setCustomAnimations(R.anim.push_right_in, R.anim.push_right_out);
						LeftFragment page2 = new LeftFragment();
						t.replace(R.id.left_frame, page2);
						t.commit();
						page2 = null;
		        	}
		            return true;
		        }
				
				return false;
			}
			
			@Override
			public boolean onDown(MotionEvent e) {
				// TODO Auto-generated method stub
				return false;
			}
		});
		aboutList.setOnTouchListener(new OnTouchListener() {
		
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				return detector.onTouchEvent(event);
			}
		});
		
		aboutList.setOnItemClickListener(new OnItemClickListener() {

			@SuppressLint("NewApi")
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				ClipboardManager clip = (ClipboardManager)mContext.getSystemService(Context.CLIPBOARD_SERVICE);
				//clip.getText(); // 粘贴
				clip.setText("@图解电影GM"); // 复制
				Toast.makeText(mContext, "账号已复制到粘贴板:)", Toast.LENGTH_SHORT).show();
			}
		});
		
		
		
		btn_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				FragmentTransaction t = getActivity().getSupportFragmentManager()
						.beginTransaction();
				t.setCustomAnimations(R.anim.push_right_in, R.anim.push_right_out);
				LeftFragment downfragment = new LeftFragment();
				t.replace(R.id.left_frame, downfragment);
				t.commit();
				downfragment = null;
			}
		});
		
		
		return view;
	}

	public void onActivityCreated(Bundle savedInstanceState) {	
		super.onActivityCreated(savedInstanceState);
	}

	public void getInfo()
	{
		mlist = new ArrayList<AboutUsInfo>();
		int[] icon = new int[]{R.drawable.snscell_sina,R.drawable.snscell_tx,R.drawable.snscell_weixin};
		String[] info1 = new String[]{"新浪微博","腾讯微博","官方微信"};
		String[] info2 = new String[]{"@图解电影GM(graphmovie)","@图解电影GM(graphmovie)","@图解电影GM"};
		for(int i=0;i<icon.length;i++)
		{
			AboutUsInfo aui = new AboutUsInfo();
			aui.setImgid(icon[i]);
			aui.setInfo_1(info1[i]);
			aui.setInfo_2(info2[i]);
			mlist.add(aui);
		}
		
		icon = null;
		info1= null;
		info2 = null;
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub				
		super.onResume();
	}
}

